package reader;

import java.io.FileReader;
import java.io.IOException;

/*
成员方法：
     int read(char[] cbuf)
          将字符读入数组。

String类的方法：
     String(char[] value)
          将一个字符数组转换成一个字符串

     String(char[] value, int offset, int count)
          分配一个新的 String，它包含取自字符数组参数一个子数组的字符。

 */
public class FileReader02 {
    public static void main(String[] args) throws IOException {
        FileReader fr = new FileReader("Day24/6.txt");
        char[] chars = new char[2];

     /*   int length = fr.read(chars);
        System.out.println(length + " " + new String(chars));//2 手表

        int length2 = fr.read(chars);
        System.out.println(length2 + " " + new String(chars));//2 电动

        int length3 = fr.read(chars);
        System.out.println(length3 + " " + new String(chars));//1 车动

        int length4 = fr.read(chars);
        System.out.println(length4 + " " + new String(chars));//-1 车动*/

    /*    int length = fr.read(chars);
        System.out.println(length + " " + new String(chars,0,length));//2 手表

        int length2 = fr.read(chars);
        System.out.println(length2 + " " + new String(chars,0,length2));//2 电动

        int length3 = fr.read(chars);
        System.out.println(length3 + " " + new String(chars,0,length3));//1 车*/

        int length;
        while ((length = fr.read(chars)) != -1) {
            System.out.println(new String(chars,0,length));
        }


        fr.close();
    }
}
